package utils

import (
	"time"
)

func TimeStrToTs(timeStr, timeFormat string) int64 {
	loc, _ := time.LoadLocation("Local")
	if timeFormat == "" {
		timeFormat = "2006-01-02 15:04:05"
	}
	theTime, _ := time.ParseInLocation(timeFormat, timeStr, loc)
	return theTime.Unix()
}

func TsToYmd(ts int64, format string) string {
	if ts <= 0 {
		ts = time.Now().Unix()
	}
	if format == "" {
		format = "20060102"
	}
	tm := time.Unix(ts, 0)
	return tm.Format(format)
}
